#ifndef MPDBACKEND_H
#define MPDBACKEND_H

#include <QObject>
#include <QtPlugin>
#include <QString>
#include <libmpd-1.0/libmpd/libmpd.h>
#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QObject>
#include <qdebug.h>
#include <QTimer>
#include "../../../src/song.h"
#include "../../../src/artist.h"
#include "../../../src/album.h"
#include "../../../src/audioplayerbackend.h"

void status_changedCB(MpdObj *mi, ChangedStatusType what, void* userData);

class mpdbackend: public AudioPlayerBackend
{
    Q_OBJECT
    Q_INTERFACES(AudioPlayerBackend)
public:
    void init();
    uint features();
    QString getCurrentSongTitle();
    QString getCurrentSongArtist();
    QString getCurrentSongAlbum();
    uint getVolume();
    bool isPlaying();
    bool isPaused();
    void statusChanged(ChangedStatusType what);

    QList<QString> getAllArtists();
    QList<QString> getAllAlbums();
    QList<Song*> * getAllSongs();
    QList<QString> getAlbumsFromArtist(QString artist);
    QList<Song*> * getSongsFromAlbum(Album * album);
    QList<Song*> * getSongsFromArtist(Artist * artist);

private:
    mpd_Song * currentSong;
    MpdObj * mpd;

signals:
    void randomStatusChanged(bool status);
    void repeatStatusChanged(bool status);
    void songChanged();
    void stateChanged(bool playing);

public slots:

    bool stop();
    bool next();
    bool prev();

    bool setVolume(int value);
    bool seek(int sec);
    int getElapsedTime();

    bool play();
    bool play(uint id);
    bool play(Song * song);
    bool pause();
    bool togglePause();

    bool setRandom(bool status);
    bool getRandom();
    bool toggleRandom();

    bool setRepeat(bool status);
    bool getRepeat();
    bool toggleRepeat();

private slots:
    void timerTimeout();
};

#endif // MPDBACKEND_H
